home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / ctlib100.zip / INSTALL.LZH / ARRAYSH1.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-12  |  3KB  |  100 lines

  1. {**************************************************************************}
  2. {*  BitSoft Development, L.L.C.                                           *}
  3. {*  Copyright (C) 1995, 1996 BitSoft Development, L.L.C.                  *}
  4. {*  All rights reserved.                                                  *}
  5. {*  Containers Library demo                                               *}
  6. {**************************************************************************}
  7.  
  8. program ArraysHuge1;
  9.  
  10. {$X+}
  11.  
  12. { Sample program for using a huge array }
  13.  
  14. uses Containr, ctArrays,
  15.      {$ifdef Windows}
  16.      WinCtr;
  17.      {$else}
  18.      Crt;
  19.      {$endif}
  20.  
  21. type
  22.   PWeatherInfo = ^TWeatherInfo;
  23.   TWeatherInfo = record
  24.     Location : string[20];
  25.     Humidity : Integer;
  26.     Rain : Integer;
  27.   end; { TWeatherInfo }
  28.  
  29. procedure SetWeatherValues(ALocation : string; AHumidity, ARain : Integer;
  30.   var WeatherRec : TWeatherInfo);
  31. begin
  32.   with WeatherRec do
  33.   begin
  34.     Location := ALocation;
  35.     Humidity := AHumidity;
  36.     Rain := ARain;
  37.   end; { with }
  38. end;
  39.  
  40. procedure DisplayWeatherData(WeatherData : PSequence);
  41. var
  42.   i : Integer;
  43. begin
  44.   with WeatherData^ do
  45.     for i := FirstIndex to LastIndex do
  46.       with PWeatherInfo(At(i))^ do
  47.         writeln('Hour: ', i:2, ':00', '':3, Location, '':20 -
  48.           Length(Location), Humidity, '':5, Rain:5);
  49. end;
  50.  
  51. procedure FindLowHumidityValue(WeatherData : PSequence);
  52. var
  53.   Item : Pointer;
  54.   Index : LongInt;
  55.  
  56.   function HasLowHumidity(Item : PWeatherInfo) : Boolean; far;
  57.   begin
  58.     HasLowHumidity := (Item^.Humidity < 22);
  59.   end;
  60.  
  61. begin
  62.   Item := WeatherData^.FirstThat(@HasLowHumidity, Index);
  63.   writeln ('First with low humidity (H < 22):');
  64.   with PWeatherInfo(Item)^ do
  65.     writeln('Hour: ', Index:2, ':00', '':3, Location, '':20 -
  66.       Length(Location), Humidity, '':5, Rain:5);
  67. end;
  68.  
  69. var
  70.   MorningWeatherData : PHugeArray;
  71.   WeatherInfo: TWeatherInfo;
  72.  
  73. begin
  74.   ClrScr;
  75.  
  76.   { Create the array }
  77.   MorningWeatherData := New(PHugeArray, Init(7, 11, SizeOf(TWeatherInfo)));
  78.  
  79.   { Insert the items in the array }
  80.   with MorningWeatherData^ do
  81.   begin
  82.     SetWeatherValues('Miami', 34, 0, WeatherInfo);
  83.     AtInsert(7, @WeatherInfo);
  84.     SetWeatherValues('Helsinski', 23, 3, WeatherInfo);
  85.     AtInsert(8, @WeatherInfo);
  86.     SetWeatherValues('Canada', 26, 2, WeatherInfo);
  87.     AtInsert(9, @WeatherInfo);
  88.     SetWeatherValues('Berlin', 28, 5, WeatherInfo);
  89.     AtInsert(10, @WeatherInfo);
  90.     SetWeatherValues('Melbourne', 20, 0, WeatherInfo);
  91.     AtInsert(11, @WeatherInfo);
  92.   end; { with }
  93.  
  94.   DisplayWeatherData(MorningWeatherData);
  95.   writeln;
  96.   FindLowHumidityValue(MorningWeatherData);
  97.  
  98.   { Dispose of the array }
  99.   Dispose(MorningWeatherData, Done);
  100. end.